#!/bin/bash

# 成 root 账户的公钥和私钥
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa;

# 将公钥输出到文件 authorized_keys 文件，并修改权限
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 400 ~/.ssh/authorized_keys

# 打开RSA验证相关设置
sed -i 's/#PubkeyAuthentication/PubkeyAuthentication/' /etc/ssh/sshd_config
sed -i '44i RSAAuthentication yes' /etc/ssh/sshd_config

# 重启ssh服务
systemctl restart sshd

scp ~/.ssh/id_rsa 
